package com.java.module.chat.service.impl;

import java.util.List;

import com.java.common.utils.AssertKit;
import com.java.common.utils.DateUtils;
import com.java.module.chat.domain.ChatGroup;
import com.java.module.chat.mapper.ChatGroupMapper;
import com.java.module.chat.domain.GroupUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.java.module.chat.mapper.GroupUserMapper;
import com.java.module.chat.service.IGroupUserService;

/**
 * 聊天模块：群成员Service业务层处理
 * 
 * @author Administrator
 * @date 2023-02-16
 */
@Service
public class GroupUserServiceImpl implements IGroupUserService 
{
    @Autowired
    private GroupUserMapper groupUserMapper;
    @Autowired
    private ChatGroupMapper chatGroupMapper;

    /**
     * 查询聊天模块：群成员
     * 
     * @param id 聊天模块：群成员ID
     * @return 聊天模块：群成员
     */
    @Override
    public GroupUser selectGroupUserById(Long id)
    {
        return groupUserMapper.selectGroupUserById(id);
    }

    /**
     * 查询聊天模块：群成员列表
     * 
     * @param groupUser 聊天模块：群成员
     * @return 聊天模块：群成员
     */
    @Override
    public List<GroupUser> selectGroupUserList(GroupUser groupUser)
    {
        return groupUserMapper.selectGroupUserList(groupUser);
    }

    /**
     * 新增聊天模块：群成员
     * 
     * @param groupUser 聊天模块：群成员
     * @return 结果
     */
    @Override
    public int insertGroupUser(GroupUser groupUser)
    {
        groupUser.setCreateTime(DateUtils.getNowDate());
        return groupUserMapper.insertGroupUser(groupUser);
    }

    /**
     * 修改聊天模块：群成员
     * 
     * @param groupUser 聊天模块：群成员
     * @return 结果
     */
    @Override
    public int updateGroupUser(GroupUser groupUser)
    {
        groupUser.setUpdateTime(DateUtils.getNowDate());
        return groupUserMapper.updateGroupUser(groupUser);
    }

    /**
     * 批量删除聊天模块：群成员
     * 
     * @param ids 需要删除的聊天模块：群成员ID
     * @return 结果
     */
    @Override
    public int deleteGroupUserByIds(Long[] ids)
    {
        return groupUserMapper.deleteGroupUserByIds(ids);
    }

    /**
     * 删除聊天模块：群成员信息
     * 
     * @param id 聊天模块：群成员ID
     * @return 结果
     */
    @Override
    public int deleteGroupUserById(Long id)
    {
        return groupUserMapper.deleteGroupUserById(id);
    }

    /**
     * 获取用户成功
     * @param groupUser
     * @return
     */
    @Override
    public List<GroupUser> getGroupUserList(GroupUser groupUser) {
        return groupUserMapper.getGroupUserList(groupUser);
    }

    /**
     * 修改用户禁言
     * @param groupUser
     * @param loginUserId
     * @return
     */
    @Override
    public int changeUserEstoppel(GroupUser groupUser, Long loginUserId) {

        Long gid = groupUser.getGid();
        Long uid = groupUser.getUid();
        Integer estoppel = groupUser.getEstoppel();
        AssertKit.notNull(gid,"信息错误");
        AssertKit.notNull(uid,"信息错误");
        AssertKit.notNull(estoppel,"信息错误");
        ChatGroup chatGroup = chatGroupMapper.selectChatGroupById(gid);
        AssertKit.notNull(chatGroup,"信息错误");
        AssertKit.isTrue(chatGroup.getUid().equals(loginUserId),"信息错误");
        return groupUserMapper.updateGroupUserEstoppel(groupUser);
    }


}
